<template>
  <div class="brand_source_material">
    <c-title text="品牌素材" :hide="false"></c-title>
    <div class="headBg">
      <!-- <i class="iconfont icon-member-left"></i> -->
      <div class="headBg_img">
        <img :src="infoData.background" alt="" />
      </div>
    </div>
    <div class="contenB">
      <div class="brandCard">
        <div class="brandCard_top">
          <div class="brandImg">
            <img :src="infoData.brand_logo" alt="" />
          </div>
          <div class="brandDetail">
            <div class="brandDetail_title" @click="bandDetailShow = true">{{ infoData.brand_name }}</div>
            <div class="brandDetail_tag">共{{ infoData.material_count }}款素材</div>
          </div>
        </div>
        <div class="brandCard_bottom" :style="{ maxHeight: hideTxt ? '3.44rem' : '' }" v-html="infoData.desc"></div>
        <div class="moreHide" @click="hideTxt = !hideTxt">
          <i class="iconfont icon-icon_down1" v-if="hideTxt"></i>
          <i class="iconfont icon-icon_up1" v-if="!hideTxt"></i>
          <div class="icontxt">{{ hideTxt ? "查看全部" : "隐藏" }}</div>
        </div>
        <!-- <div class="brandCard_copy" v-clipboard:copy="infoData.main_desc" v-clipboard:success="onCopy" v-clipboard:error="onError">复制文案</div> -->
      </div>
      <div class="tabBox">
        <van-tabs v-model="active" @change="tabChange" background="transparent" :ellipsis="false" line-width="26px" title-active-color="#00001C" title-inactive-color="#808080">
          <van-tab title="全部" :title-style="active == 0 ? 'font-size: 0.94rem;font-weight: bold;' : ''"></van-tab>
          <van-tab :title="item.name" v-for="item in cateList" :name="item.id" :key="item" :title-style="active == item.id ? 'font-size: 0.94rem;font-weight: bold;' : ''"></van-tab>
        </van-tabs>
        <div class="list">
          <div class="lis" @click="toDetail(item.id)" v-for="item in dataList" :key="item.id">
            <div class="lis_img" v-if="item.images.length > 0 || (item.videos && item.videos.video_image)">
              <img :src="item.images[0]" alt="" v-if="item.images.length > 0" />
              <img :src="item.videos.video_image" alt="" v-else-if="item.videos && item.videos.video_image" />
            </div>
            <div class="lis_bottom">
              <div class="source_material_lis_title">
                <div :class="item.goods.status == 0?'tag mdtag':'tag'">{{ item.goods.status == 1 ? "在售" : "售罄" }}</div>
                {{ item.title }}
              </div>
              <div class="memberBox">
                <img :src="item.logo" class="memberBox_img" alt="" />
                <div class="memberBox_txt">{{ item.name }}</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
import { Toast } from "vant";
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      hideTxt: true,
      active: 0,
      infoData: [],
      page: 1,
      total_page: 0,
      isLoadMore: true,
      cateList: [],
      dataList: []
    };
  },
  activated() {
    this.getCate();
    this.getData();
  },
  methods: {
    tabChange() {
      this.init();
      this.getGood();
    },
    init() {
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
      this.dataList = [];
    },
    toDetail(key) {
      this.$router.push(this.fun.getUrl("brand_source_detail", { id: key }));
    },
    async getCate() {
      let { data, msg, result } = await $http.post("plugin.material-center.api.centerlist.firstCategoryList", { brand_id: this.$route.params.id }, "");
      if (result) {
        this.cateList = data;
        this.active = 0;
        this.init();
        this.getGood();
      } else {
        this.$toast(msg);
      }
    },
    async getData() {
      let json = {
        brand_id: this.$route.params.id
      };

      let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.brand.index", json, "");
      if (result) {
        this.infoData = data;
      } else {
        this.$toast(msg);
      }
    },
    async getGood() {
      let json = {
        brand_id: this.$route.params.id
      };
      if (this.active) {
        json.parentid = this.active;
      }
      let { data, msg, result } = await $http.post("plugin.material-center.api.centerlist.index", json, "");
      if (result) {
        this.dataList = data.list.data;
        this.total_page = data.list.last_page;
        this.isLoadMore = true;
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          page: this.page,
          brand_id: this.$route.params.id
        };
        if (this.active) {
          json.parentid = this.active;
        }
        let { data, msg, result } = await $http.post("plugin.material-center.api.centerlist.index", json, "");
        this.isLoadMore = true;
        if (result) {
          this.dataList = this.dataList.concat(data.list.data);
        } else {
          this.page = this.page - 1;
          this.$toast(msg);
        }
      }
    },
    onCopy(e) {
      Toast({
        message: "复制成功",
        position: "bottom",
        duration: 500
      });
    },
    onError(e) {
      Toast({
        message: "复制失败",
        position: "bottom",
        duration: 1000
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.tabBox {
  .list {
    display: flex;
    flex-wrap: wrap;
    padding: 0.47rem 0;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: flex-start;
    .lis {
      width: 10.78rem;
      border-radius: 0.75rem;
      background: #ffffff;
      margin-bottom: 0.38rem;
      .lis_img {
        width: 10.78rem;
        height: 10.78rem;
        border-radius: 0.75rem 0.75rem 0 0;
        background: #aaaab3;
        img {
          width: 100%;
          height: 100%;
          border-radius: 0.75rem 0.75rem 0 0;
        }
      }
      .lis_bottom {
        padding: 0.47rem 0.5rem;
        box-sizing: border-box;
        .source_material_lis_title {
          text-align: left;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          overflow: hidden;
          text-overflow: ellipsis;
          .tag {
            display: inline-block;
            font-weight: 500;
            font-size: 0.75rem;
            line-height: 0.9rem;
            color: #ffffff;
            padding: 0.16rem 0.22rem;
            background: #f96d20;
            border-radius: 0.31rem;
            margin-right: 0.3rem;
          }
          .mdtag {
            background: #999;
          }
        }
        .memberBox {
          display: flex;
          align-items: center;
          margin-top: 0.66rem;
          .memberBox_img {
            width: 1.5rem;
            height: 1.5rem;
            background: #e9e9e9;
            margin: 0;
            margin-right: 0.44rem;
            border-radius: 50%;
          }
          .memberBox_txt {
            font-size: 0.81rem;
            color: #6e6e79;
            line-height: 0.94rem;
          }
        }
      }
    }
  }
}
.headBg {
  height: 11.25rem;
  font-size: 1rem;
  color: #ffffff;
  text-align: left;
  overflow: hidden;
  box-sizing: border-box;
  .headBg_img {
    width: 100%;
    height: 100%;
    position: relative;
  }
  .headBg_img::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2);
  }
  img {
    width: 100%;
    height: 100%;
    display: block;
  }
}
.contenB {
  position: relative;
  margin-top: -0.63rem;
  background: #f5f5f5;
  border-radius: 0.63rem;
  padding: 1.47rem 0.75rem 0 0.75rem;
  box-sizing: border-box;
  .brandCard {
    background: #ffffff;
    border-radius: 0.63rem;
    margin-top: -4.3rem;
    padding: 0.84rem 0.5rem;
    .brandCard_top {
      display: flex;
      justify-content: space-between;
      .brandImg {
        width: 3rem;
        height: 3rem;
        background: #ffffff;
        border-radius: 0.5rem;
        border: 0.03rem solid #e9e9e9;
        margin-right: 0.38rem;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .brandDetail {
        flex: 1;
        text-align: left;
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        .brandDetail_title {
          font-weight: bold;
          font-size: 1rem;
          color: #00001c;
        }
        .brandDetail_tag {
          font-size: 0.75rem;
          color: #808080;
        }
      }
    }
    .brandCard_copy {
      width: 8.13rem;
      height: 2rem;
      border-radius: 1rem 1rem 1rem 1rem;
      border: 0.03rem solid #f15353;
      font-size: 0.81rem;
      color: #f15353;
      margin: 0 auto;
      line-height: 2rem;
      margin-top: 0.47rem;
    }
    .brandCard_bottom {
      overflow: hidden;
      position: relative;
      text-align: left;
      margin-top: 0.47rem;
    }
  }
}
.moreHide {
  background: #ffffff;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-left: 0.5rem;
  box-sizing: border-box;
  margin-top: 0.5rem;
  .icon-icon_down1 {
    font-size: 1rem;
    color: #aaaab3;
  }
  .icon-icon_up1 {
    font-size: 1rem;
    color: #aaaab3;
  }
  .icontxt {
    color: #aaaab3;
    margin-left: 0.25rem;
  }
}
</style>
